#include "VulkanVertexDeclaration.h"
#include "CGIVulkan.h"
#include "Runtime/Misc/Crc.h"

namespace Alice
{
    VulkanVertexDeclarationKey::VulkanVertexDeclarationKey(const VertexDeclarationElementList& inVertexDeclarationElementList)
        :mVertexDeclarationElementList(inVertexDeclarationElementList)
    {
        mHash = Crc::MemCrc32(inVertexDeclarationElementList.data(), inVertexDeclarationElementList.size()*sizeof(FVertexElement));
        mHashNoStrides = 0;
        for (int32 ElementIndex = 0; ElementIndex < inVertexDeclarationElementList.size(); ElementIndex++)
        {
            FVertexElement Element = inVertexDeclarationElementList[ElementIndex];
            Element.mStride = 0;
            mHashNoStrides = Crc::MemCrc32(&Element, sizeof(Element), mHashNoStrides);
        }
    }
    VulkanVertexDeclaration::VulkanVertexDeclaration(const VertexDeclarationElementList& inVertexDeclarationElementList, uint32 inHash, uint32 inHashNoStrides)
        :mVertexDeclarationElementList(inVertexDeclarationElementList),mHash(inHash),mHashNoStrides(inHashNoStrides)
    {
        
    }
    CGIVertexDeclaration* CGIVulkan::RHICreateVertexDeclaration(const VertexDeclarationElementList& Elements)
    {
        VulkanVertexDeclarationKey vulkanVertexDeclarationKey(Elements);
        VulkanVertexDeclaration*vertexDeclaration=new VulkanVertexDeclaration(Elements,vulkanVertexDeclarationKey.mHash,vulkanVertexDeclarationKey.mHashNoStrides);
        return vertexDeclaration;
    }
}
